package tasktracker.core.loader;

import java.util.HashMap;
import java.util.Map;

import tasktracker.abstraction.ITaskTracker;
import tasktracker.abstraction.ITaskTrackerFactory;

public class SimpleClassLoaderTaskTrackerFactory implements ITaskTrackerFactory {

	private String name;
	private String trackerClass;

	public SimpleClassLoaderTaskTrackerFactory() {
	}

	public SimpleClassLoaderTaskTrackerFactory(String name, String trackerClass) {
		this.name = name;
		this.trackerClass = trackerClass;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTrackerClass() {
		return trackerClass;
	}

	public void setTrackerClass(String trackerClass) {
		this.trackerClass = trackerClass;
	}

	@Override
	public Map<String, ITaskTracker> getInstances() {
		try {
			Class<?> c = Class.forName(trackerClass);
			ITaskTracker tracker = (ITaskTracker) c.newInstance();
			Map<String, ITaskTracker> map = new HashMap<String, ITaskTracker>(1);
			map.put(name, tracker);
			return map;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
